#include "MFile.h"

GPtrArray *FileColumnJsonDecode(JsonObject *object_member){
    JsonNode *_node = json_object_get_member(object_member,"data");
    JsonArray *array = json_object_get_array_member(json_node_get_object(_node),"FileList");
    GList *my_list = json_array_get_elements(array);
    GPtrArray *result_list = g_ptr_array_new();
    for(;my_list!=NULL;my_list = my_list->next){
        JsonObject *each_object = json_node_get_object(my_list->data);
        FileModel *_fm = filemodel_new(each_object);
        g_ptr_array_add(result_list,(gpointer)_fm);
    }
    return result_list;
}

GPtrArray *FileColumnArray(JsonObject *object_member){
    JsonNode *_node = json_object_get_member(object_member,"data");
    JsonArray *array = json_object_get_array_member(json_node_get_object(_node),"ColumnList");
    int array_length = json_array_get_length(array);
    GPtrArray *result = g_ptr_array_new();
    int mos = 0;
    g_ptr_array_add(result,(gpointer)array_length);
    for(mos;mos<array_length;mos++){
        g_ptr_array_add(result,(gpointer)json_array_get_string_element(array,mos));
    }
    return result;
}

FileModel *filemodel_new(JsonObject *each_object){
    FileModel *_file = (FileModel *)malloc(sizeof(struct _FileModel));
    _file->id = json_object_get_int_member(each_object,"id");
    _file->name = json_object_get_string_member(each_object,"name");
    _file->filename = json_object_get_string_member(each_object,"filename");
    _file->url= json_object_get_string_member(each_object,"url");
    _file->uploader_name= json_object_get_string_member(each_object,"uploader_name");
    _file->suffixname = json_object_get_string_member(each_object,"suffixname");
    return _file;
}
